package oop.ex1.actions;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;



/**
 * a subclass that changes the file last modification date to a selected date.
 * @author danalmog
 * @author danielshalev
 */
public class LastMod extends Actions {
	private String date;
	private final SimpleDateFormat FORM = new SimpleDateFormat("dd/MM/yyyy");
	private File file;

	/**
	 * a constructor that gets a date and save it to a local variable
	 * @param date FORM
	 */
	public LastMod(String date,File file){
		super(file);
		this.file=file;
		this.date=new String(date);
	}
	
	/**
	 * sets the LastMod date to the desired date
	 * @throws ActionDateExeption indicates the parameter that was entered is not a date 
	 */
	public void doAction() throws ActionDateException{
		Date mod;
		try {
			mod = FORM.parse(date);
		} catch (ParseException e) {
			throw new ActionDateException(e.getMessage(),e.getErrorOffset());
		}
		file.setLastModified(mod.getTime());
	}
}